<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>用户信息编辑</title>
<%@include file="/common/wxCommon.jspf"%>
</head>
<body ontouchstart>
	<header class="page-header">
      <h1 class="page-title">编辑信息</h1>
    </header>
	<form method="post" action="${ctx }/weixin/user/saveMyinfo.shtml" id="form">
		<input type="hidden" value="${weixinUser.id }" name="weixinUserFormMap.id">
		<%--活动扫码链接参数 --%>
		<input type="hidden" value="${param.partyId }" name="partyId">
		<input type="hidden" value="${param.type }" name="type">
		<div class="weui_cells weui_cells_form">
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label"><span class="required">*</span>姓&emsp;&emsp;名</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" placeholder="真实姓名" name="weixinUserFormMap.name"
						value="${weixinUser.name }">
				</div>
				<div class="weui_cell_ft">
		          <i class="weui_icon_warn"></i>
		        </div>
			</div>
			<div class="weui_cell">
		        <div class="weui_cell_hd"><label class="weui_label"><span class="required">*</span>性&emsp;&emsp;别</label></div>
		        <div class="weui_cell_bd weui_cell_primary">
		          <input class="weui_input" id="selectSex" name="selectSex" type="text"
						 value="${weixinUser.sex eq 0 ? '' : weixinUser.sex eq 1 ? '男' : '女'}"
		          	 	 readonly="" data-values="${weixinUserFormMap.sex }" placeholder="请选择性别">
		          <input name="weixinUserFormMap.sex" id="weixinUserFormMap_sex" type="hidden"
						 value="${weixinUser.sex eq 0 ? '' : weixinUser.sex}">
		        </div>
		        <div class="weui_cell_ft ">
					<i class="weui_icon_warn"></i>
				</div>
		    </div>
		    <div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">&nbsp;&thinsp;年&emsp;&emsp;龄</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" id="" placeholder="真实年龄" name="weixinUserFormMap.age"
						value="${weixinUser.age }">
				</div>
				<div class="weui_cell_ft">
		          <i class="weui_icon_warn"></i>
		        </div>
			</div>
		    <div class="weui_cell">
		        <div class="weui_cell_hd"><label class="weui_label">&nbsp;&thinsp;政治面貌</label></div>
		        <div class="weui_cell_bd weui_cell_primary">
		          <c:forEach items="${politicalList }" var="record">
		          	<c:if test="${record.value eq weixinUser.political }">
		          		<c:set var="political" value="${record.label }"></c:set>
		          	</c:if>
		          </c:forEach>
		          <input class="weui_input" id="selectPolitical" name="selectPolitical" type="text"
						 value="${political }" readonly="" data-values="${weixinUser.political }" placeholder="请选择政治面貌">
		          <input name="weixinUserFormMap.political" id="weixinUserFormMap_political" type="hidden"
						 value="${weixinUser.political}">
		        </div>
		        <div class="weui_cell_ft ">
					<i class="weui_icon_warn"></i>
				</div>
		    </div>
		    <div class="weui_cell ${(weixinUser.political eq 0 or weixinUser.political eq 1) ? '' : 'hide' }" id="unitOrg">
				<div class="weui_cell_hd">
					<label class="weui_label">&nbsp;组织关系<br/>&nbsp;所属单位</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" id="weixinUserFormMap_unitOrg" placeholder="组织关系所属单位"
						name="weixinUserFormMap.unitOrg" value="${weixinUser.unitOrg }">
				</div>
			</div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label"><span class="required">*</span>联系方式</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" id="" placeholder="手机号码" name="weixinUserFormMap.mobile"
						value="${weixinUser.mobile }">
				</div>
				<div class="weui_cell_ft">
		          <i class="weui_icon_warn"></i>
		        </div>
			</div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">&nbsp;&thinsp;电子邮件</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" id="" placeholder="电子邮件" name="weixinUserFormMap.email"
						value="${weixinUser.email }">
				</div>
				<div class="weui_cell_ft">
		          <i class="weui_icon_warn"></i>
		        </div>
			</div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">&nbsp;&thinsp;兴趣爱好</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input type="text" class="weui_input" id="" placeholder="兴趣爱好"
						name="weixinUserFormMap.interest" value="${weixinUser.interest }">
				</div>
			</div>
			<div class="weui_cell weui_cell_select">
				<div class="weui_cell_bd weui_cell_primary">
					<select class="weui_select" name="weixinUserFormMap.province">
					</select>
				</div>
			</div>
			<div class="weui_cell weui_cell_select">
				<div class="weui_cell_bd weui_cell_primary">
					<select class="weui_select" name="weixinUserFormMap.city">
					</select>
				</div>
			</div>
			<div class="weui_cell weui_cell_select">
				<div class="weui_cell_bd weui_cell_primary">
					<select class="weui_select" name="weixinUserFormMap.area">
					</select>
				</div>
			</div>
		</div>
		<div class="content-padded">
			<button type="submit" class="weui_btn weui_btn_warn">保存${param.type eq 0 ? '及报名活动' : (param.type eq 1 ? '及签到活动' : '') }</button>
			<a href="${ctx }/weixin/user/myinfo.shtml" class="weui_btn weui_btn_default">取消</a>
		</div>
	</form>
	<script type="text/javascript">
		$(function() {
			<c:if test="${not empty weixinUser.name }">
			initRegionFormControl("${weixinUser.province}","${weixinUser.city}","${weixinUser.area}");//初始化省市区
			</c:if>
			<c:if test="${empty weixinUser.name }">
			initRegionFormControl();//初始化省市区
			</c:if>

			//jquery form验证
			$("#form").validate({
				submitHandler: function(form) {
					form.submit();
				},
				success: function(error, element) { 
					//验证通过时
					$(element).parents(".weui_cell").removeClass("weui_cell_warn");
				},
				errorPlacement: function(error, element) {
					//验证失败时
					$(element).parents(".weui_cell").addClass("weui_cell_warn");
				},
				rules: {
					"weixinUserFormMap.name": "required",
					"weixinUserFormMap.mobile": {required: true, minlength: 11 },
					"weixinUserFormMap.age": {digits: true, range: [1, 130]  },
					"selectSex": "required",
					"weixinUserFormMap.email": {required: false, email: true }
				}
			});
			
			$("#selectSex").select({
		        title: "性别",
		        items: [
			      	{title : "男", value : 1},
			      	{title : "女", value : 2},
		        ],
		        onChange: function(d) {
		            $("#weixinUserFormMap_sex").val(d.values);
		        }
		    });
			
			$("#selectPolitical").select({
		        title: "政治面貌",
		        items: [
		          <c:forEach items="${politicalList }" var="record">
			      	{title : "${record.label }", value : "${record.value }"},
			      </c:forEach>
		        ],
		        onChange: function(d) {
		            $("#weixinUserFormMap_political").val(d.values);
		            if (d.values == 0 || d.values == 1) {
		            	$("#unitOrg").removeClass("hide");
		            } else {
		            	$("#weixinUserFormMap_unitOrg").val("");
		            	$("#unitOrg").addClass("hide");
		            }
		        }
		    });
		});
	</script>
</body>
</html>